package com.liam.lotterysystem.common.utils;

import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;

/**
 * @Author: LiamLMK
 * @CreateTime: 2024-10-14
 * @Description:
 * @Version: 1.0
 */

public class CaptureUtil {
    /**
     * 生成随机验证码
     * @param length
     * @return
     */
    public static String getCaptcha(int length) {
        // 自定义纯数字验证码(随机四位数字, 可重复)
        RandomGenerator randomGenerator = new RandomGenerator("0123456789", length);
        LineCaptcha lineCaptcha =
                cn.hutool.captcha.CaptchaUtil.createLineCaptcha(200, 100);
        lineCaptcha.setGenerator(randomGenerator);
        // 重新⽣成code
        lineCaptcha.createCode();
        return lineCaptcha.getCode();
    }
}
